// packagePay/pages/insurance-success/insurance-success.js
import {
    insuranceReportDetail,
    revokeReportCase,
    getInsureCompanyList
} from '../../api/insurance'
import {
    confirm,
    toast
} from '../../../utils/util'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        detailInfo: {},
        result: []
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        console.log(options, 'options')
        this.getInsuranceReportDetail(options.id)
    },
    getInsuranceReportDetail(id) {
        insuranceReportDetail({
            id: id
        }).then(async res => {
            const insureCompanyList = await getInsureCompanyList() || []
            res.canShowAddMaterial = insureCompanyList.some(i => i === res.insureCompanyType)
            // res.params.fileUrl.forEach((item,index)=>{
            //     res.params.fileUrl[index].fileUrl = JSON.parse(item.fileUrl)
            // })
            this.setData({
                result: res.results,
                detailInfo: res,
            })
        })
    },
    // 撤销报案
    async onRevokeReportCase(event) {
        console.log(event, 'event')
        confirm('确认撤销当前报案吗').then(() => {
            revokeReportCase({
                id: this.data.detailInfo.id
            }).then(() => {
                this.getInsuranceReportDetail(this.data.detailInfo.id)
                toast('撤销成功')
            })
        })

    },
    onPreview(event) {
        const {
            url
        } = event.currentTarget.dataset
        wx.previewImage({
            urls: [url]
        })
    },
    onPlay(event) {
        console.log(event.currentTarget.id)
        console.log(this, 'this')
        // 获取 video 上下文 videoContext 对象
        this.videoContext = wx.createVideoContext(event.currentTarget.id, this)
        // 进入全屏状态
        this.videoContext.requestFullScreen()
        return 0
    },

    toExtraMaterial(event) {
        const { type, id } = event.currentTarget.dataset
        wx.navigateTo({
            url: `/packageInsurance/pages/extra-material/extra-material?insureType=day&insureCompany=${type}&id=${id}`
        })
    }
})